package com.proxy;

import com.proxy.service.UserService;
import com.proxy.service.impl.UserServiceImpl;

import java.lang.reflect.Proxy;

public class ProxyApplication {
    public static void main(String[] args) {
        // 动态代理必须实现了接口才能使用，否则一定报错
        UserService userService = new UserServiceImpl();
        UserService proxyInstance = (UserService) Proxy.newProxyInstance(userService.getClass().getClassLoader(),
                userService.getClass().getInterfaces(),
                new ProxyInvocationHandler(userService));
        proxyInstance.createUser();
    }
}
